<template>
	<view class="prefer-content">
		<view class="prefer-title">发布委托</view>

		<view class="publish-frame">
			<block v-for="(item, index) in titleArr" :key="index">
				<view class="publish-cata shadow" @click="showEntrust(address,item.type)">
					<view class="publish-content">
						<text>{{ item.title }}</text>
						<text>{{ item.label }}</text>
					</view>
					<view><image :src="item.img" class="publish-image"></image></view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	var { log } = console;
	import {errdata} from '../../../api/errdata.js';
	// 解构console
	var { log } = console;
	// 定义数据库
	var db = wx.cloud.database()
	var users = db.collection('user')
export default {
	
	
	props: {
		address: '',
		id:''		// 用户唯一标识
	},
	
	
	data() {
		return {
			// 轮播数组
			titleArr: [
				{
					img: require('../../../static/inster/chushou.png'),
					title: '有房出售',
					label: '全程优质服务',
					type:'1'
				},
				{
					img: require('../../../static/inster/chuzu.png'),
					title: '有房出租',
					label: '放心托管',
					type:'2'
				},
				{
					img: require('../../../static/inster/maifang1.png'),
					title: '我要买房',
					label: '定制推荐',
					type:'3'
				},
				{
					img: require('../../../static/inster/zufang3.png'),
					title: '我要租房',
					label: '快速响应',
					type:'4'
				}
			]
		};
	},
	
	
	methods:{
		// 请求数据库看看用户有没有登录
		ifUser(address,type) {
			users
				.get()
				.then(res => {
					console.log(res);
					
					if (res.data.length === 0) {
						let errs = '请先登录'
						errdata.errlist(errs)
					} else {
						log('已登录')
						this.id = res.data[0]._openid;
						let id = this.id;
						
						
						log('父页面传入的地址:'+address)
						let obj = {address:address,id:id,type:type }
						let objStr = JSON.stringify(obj);
						log("objStr:"+objStr)
						
						wx.navigateTo({
							url: 'publish/publish?obj='+objStr
						});
					}
					
				})
				.catch(err => {
					console.log(err);
				});
				
			
		},
		
		showEntrust(address,type){
			this.ifUser(address,type);
		}
	}
};
</script>

<style scoped>
/* 发布委托 */

.prefer-title{
	height: 35upx;
	font-size: 35upx;
	font-weight: bold;
	margin-bottom: 40upx;
	letter-spacing: 3upx;
}
.publish-v{
	margin: 40upx 30upx 0 30upx;
	width: 90%;
}

.publish-frame {
	border-radius: 20upx;
	padding-top: 12upx;
	height: 327upx;
	width: 100%;
	display: flex;
	/* justify-content: space-between; */
	justify-content: space-around;
	flex-wrap: wrap;
	/* background-color: #f9f9f9; */
	background-color: #FFFFFF;
	
}
.publish-cata {
	width: 48%;
	height: 150upx;
	background-color: #ffffff;
	display: flex;
	align-items: center;
	justify-content: space-around;
	border-radius: 15upx;
	boxshadow: 11px 10px 5px #c6c6c6;
}

.publish-content {
	display: flex;
	flex-direction: column;
}
.publish-content text:nth-child(1) {
	padding-bottom: 7upx;
	font-size: 30upx;
	font-weight: bold;
	letter-spacing: 3upx;
}
.publish-content text:nth-child(2) {
	font-size: 25upx;
	color: #666666;
}
.publish-image {
	width: 90upx;
	height: 90upx;
}
.shadow{
	box-shadow:#F7F7F7 0px 0px 20px;
}

</style>
